const api = require("../../utils/api")

// pages/order/order.js
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    currtab: 0,
    swipertab: [{ name: '全部订单', index: 0 }, { name: '待付款', index: 1 }, { name: '售后', index: 2 }],
    OrderDateList:{},

  },
  getOrderData:function (params) {
    var token = wx.getStorageSync('token')
    wx.request({
      url:api.OrderListApi,
      dataType: "json",
      method: "get",
      header: {'Authorization':'JWT'+' '+token},
      success: (result) => {
        // 赋值
        this.setData({
          OrderDateList:result.data.data
        })
     // 获取页面数据
     this.orderShow()
      },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 获取数据
    this.getOrderData()

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  // 支付
  addToPay(e) {
    // 进行支付

    // console.log(e)
    let orderid =e.target.dataset.id
    let goodId = e.target.dataset.good_id
    // console.log(goodId)
    // 跳转页面
    wx.navigateTo({
      url: '/pages/endpay/endpay?Id=' + goodId+'&orderId=' + orderid,
    })
  },

  onReady: function () {
    // 页面渲染完成
    this.getDeviceInfo()
    // 获取订单信息
    // this.getOrderData()
  },
 
  getDeviceInfo: function () {
    let that = this
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          deviceW: res.windowWidth,
          deviceH: res.windowHeight
        })
      }
    })
  },
 
  /**
  * @Explain：选项卡点击切换
  */
  tabSwitch: function (e) {
    var that = this
    if (this.data.currtab === e.target.dataset.current) {
      return false
    } else {
      that.setData({
        currtab: e.target.dataset.current
      })
    }
  },
 
  tabChange: function (e) {
    this.setData({ currtab: e.detail.current })
    this.orderShow()
  },
 
  orderShow: function () {
    let that = this
    // 默认为o
    switch (this.data.currtab) {
      case 0:
        that.alreadyShow()
        break
      case 1:
        that.waitPayShow()
        break
      case 2:
        that.lostShow()
        break
    }
  },
  alreadyShow: function(){

    this.setData({
      alreadyOrder:this.data.OrderDateList.alreadyOrder
    })
  },
 
  waitPayShow:function(){
    this.setData({
      waitPayOrder:this.data.OrderDateList.waitPayOrder,
    })
  },
 
  lostShow: function () {
    this.setData({
      lostOrder: this.data.OrderDateList.lostOrder,
    })
  },
 
  
})